package Top200;

import common.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangmin
 * @create 2022-02-17 11:20
 * 直接模拟
 */
public class convert06 {
    public String convert(String s, int numRows) {
        if (numRows==1||s.length()<numRows) return s;
        List<StringBuffer> list=new ArrayList<>();
        for (int i = 0; i < Math.min(s.length(),numRows); i++) {
            list.add(new StringBuffer());
        }
        int currow=0;
        boolean isDown=false;
        for (char c:s.toCharArray()) {
            list.get(currow).append(c);
            if (currow==0||currow==numRows-1) isDown=!isDown;
            currow+=isDown?1:-1;
        }
        StringBuffer sb=new StringBuffer();
        for (StringBuffer l:list) {
            sb.append(l);
        }
        return sb.toString();
    }
}
